<?php
declare (strict_types=1);

namespace app\common\model;

use think\Model;

//上传日志数据表
class UploadListModel extends Model
{
    protected $table = 'utf8mb4_upload_list';

    public $from_list = [1 => '控件', 2 => '编辑器'];

    //添加一个上传日志
    public function addLog(int $uid, string $url, int $from, string $introduce)
    {
        $info = parse_url($url);
        if (empty($info)) {
            set_log('upload', 'url:' . $url . '| url parse_url is error', 'error');
            return false;
        }
        $ext = strtolower(substr(strrchr($info['path'], '.'), 1));
        $data = [
            'name' => basename($info['path']),
            'uid' => $uid,
            'from' => $from,
            'url' => $url,
            'ext' => $ext,
            'introduce' => $introduce
        ];
        return self::create($data);
    }

}